package by.sjc.grsu.dao.repositiory.impl;

import by.sjc.grsu.dao.base.AbstractHibernateDao;
import by.sjc.grsu.dao.repositiory.PeriodicalsDao;
import by.sjc.grsu.model.Periodical;
import org.hibernate.criterion.CriteriaSpecification;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@Transactional
public class PeriodicalsRepository  extends AbstractHibernateDao<Periodical, Integer> implements PeriodicalsDao {
    @Override
    public boolean isExist(String name) {
        return 0 < getSession().createCriteria(Periodical.class)
                .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
                .add( Restrictions.eq("name",name) )
                .list().size();
    }
}
